// ConfigAgentPage.cpp : implementation file
//

#include "stdafx.h"
#include "SFDL3.h"
#include "ConfigAgentPage.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CConfigAgentPage property page

IMPLEMENT_DYNCREATE(CConfigAgentPage, CPropertyPage)

CString CConfigAgentPage::TTSModeIDs[]=
{
	"{CA141FD0-AC7F-11D1-97A3-006008273002}",
		"{CA141FD0-AC7F-11D1-97A3-006008273008}",
		"{CA141FD0-AC7F-11D1-97A3-006008273009}",
		"{CA141FD0-AC7F-11D1-97A3-006008273004}",
		"{CA141FD0-AC7F-11D1-97A3-006008273007}",
};

CConfigAgentPage::CConfigAgentPage(CConfiguration* config)
	: CPropertyPage(CConfigAgentPage::IDD),
	m_pConfig(config)
{
	//{{AFX_DATA_INIT(CConfigAgentPage)
	//}}AFX_DATA_INIT
}

CConfigAgentPage::~CConfigAgentPage()
{
}

void CConfigAgentPage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CConfigAgentPage)
	DDX_Control(pDX, IDC_COMBO_TTS, m_CmbTTS);
	DDX_Control(pDX, IDC_COMBO_CHARACTER, m_CmbChar);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CConfigAgentPage, CPropertyPage)
	//{{AFX_MSG_MAP(CConfigAgentPage)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CConfigAgentPage message handlers

void CConfigAgentPage::OnOK() 
{
	// TODO: Add your specialized code here and/or call the base class
	m_CmbChar.GetLBText(m_CmbChar.GetCurSel(), m_pConfig->m_CharacterKeyStr);
	m_CmbTTS.GetLBText(m_CmbTTS.GetCurSel(), m_pConfig->m_TTSModeId);
	
	CPropertyPage::OnOK();
}

BOOL CConfigAgentPage::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	// TODO: Add extra initialization here

	// Init UI

	// Load Chars list

	char szWinDir[100];
	GetWindowsDirectory(szWinDir, 100);

	CString csFilter;
	csFilter.Format("%s\\msagent\\chars\\*.acs", szWinDir);

	WIN32_FIND_DATA findData;
	HANDLE hFind = FindFirstFile(csFilter,&findData);

	if (hFind!=INVALID_HANDLE_VALUE)
	{
		do 
		{
			m_CmbChar.AddString(findData.cFileName);
		} while (FindNextFile(hFind, &findData));
	}

	// Add TSS engine list
	for (int i=0;i<sizeof(TTSModeIDs)/sizeof(TTSModeIDs[0]);i++)
	{
		m_CmbTTS.AddString(TTSModeIDs[i]);
	}


	// Data binding
	m_CmbChar.SetCurSel(m_CmbChar.FindStringExact(0, m_pConfig->m_CharacterKeyStr));
	m_CmbTTS.SetCurSel(m_CmbTTS.FindStringExact(0,m_pConfig->m_TTSModeId));
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
